<template>
	<!-- app 签到 -->
	<view class="sing-in-div">
		<view class="sing-in-div-body">
			<view class="sing-in">
				<view class="sing-in-img">
					<image :src='nosignin' mode="aspectFit"></image>
				</view>
				<view class="sing-in-message">
					<text class="sing-in-message-p">签到情况如下</text>
					<view class="students-list-container">
						<view class="students-list" v-for="(student, index) in paginatedStudents" :key="index">
							<text>{{ student.name }}</text>
							<text class="status">{{ student.signStatus }}</text>
						</view>
					</view>
					<!-- 分页 -->
					<view class="page-help-div">
						<view class="page-help-p">
							<text @click="goToPage(1)">首页</text>
							<text @click="prevPage" :class="{ disabled: currentPage === 1 }">上一页</text>
							<text>{{ currentPage }}</text>
							<text @click="nextPage" :class="{ disabled: currentPage === totalPages }">下一页</text>
							<text @click="goToPage(totalPages)">尾页</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		computed
	} from 'vue';
	import nosignin from '../../static/noSingIn.png';

	// 学生列表数据
	const students = ref([{
			name: "李四",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "未签到"
		},
		{
			name: "zhangsan",
			signStatus: "未签到"
		},
		{
			name: "zhangsan",
			signStatus: "已签到"
		},
		{
			name: "zhangsan",
			signStatus: "未签到"
		},
		{
			name: "zhangsan",
			signStatus: "未签到"
		}
	]);

	// 每页显示的条目数
	const pageSize = ref(5);

	// 当前页码
	const currentPage = ref(1);

	// 总页数计算属性
	const totalPages = computed(() => Math.ceil(students.value.length / pageSize.value));

	// 分页后的学生数据计算属性
	const paginatedStudents = computed(() => {
		const start = (currentPage.value - 1) * pageSize.value;
		const end = start + pageSize.value;
		return students.value.slice(start, end);
	});

	// 跳转到指定页
	const goToPage = (page) => {
		if (page >= 1 && page <= totalPages.value) {
			currentPage.value = page;
		}
	};

	// 上一页
	const prevPage = () => {
		if (currentPage.value > 1) currentPage.value--;
	};

	// 下一页
	const nextPage = () => {
		if (currentPage.value < totalPages.value) currentPage.value++;
	};
</script>

<style scoped>
	.sing-in-div {
		background-color: transparent;
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 1000;
	}

	.sing-in-div-body {
		background-color: beige;
		width: 90%;
		height: 90%;
		display: flex;
		justify-content: center;
		align-items: center;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
		border-radius: 8px;
	}

	.sing-in {
		position: relative;
		background-color: white;
		width: 660px;
		height: 390px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
		border-radius: 8px;
	}

	.sing-in-img {
		position: absolute;
		top: -120px;
	}

	image {
		width: 220px;
	}

	.sing-in-message {
		position: absolute;
		top: 70px;
		text-align: center;
	}

	.sing-in-message-p {
		font-size: 18px;
		font-weight: 900;
	}

	.students-list-container text {
		margin-bottom: 0.5rem;
	}

	.students-list-container {
		margin-top: 1rem;
		width: 330px;
		height: 200px;
		overflow: hidden;
		position: relative;
	}

	.students-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: 1rem;
	}

	.students-list text {
		background-color: #f0f0f0;
		padding: 0.8rem;
		border-radius: 4px;
		flex: 0 0 auto;
		width: 5rem;
		height: 0.8rem;
		line-height: 0.8rem;
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		font-size: 16px;
	}

	/* .page-help-div {
  margin-top: 5px;
  } */


	.page-help-p text {
		padding: 3px 5px;
		border: 1px gray solid;
		margin-right: 5px;
		cursor: pointer;
		font-size: 14px;
	}

	.page-help-p text.disabled {
		color: #ccc;
		border-color: #ccc;
		cursor: not-allowed;
	}
</style>